﻿using Jive.Network;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace Jive.Models
{
    public class MessageModel : INotifyPropertyChanged
    {
        public bool IsLastInBatch { get; set; }
        //public string UserID { get; private set; }
        //public string UserName { get; private set; }
        public DateTime TimeStamp { get; private set; }

        private string _userID;
        public string UserID
        {
            get { return _userID; }
            set
            {
                if (_userID != value)
                {
                    _userID = value;
                    RaisePropertyChanged("UserID");
                }
            }
        }

        private string _userName;
        public string UserName
        {
            get { return _userName; }
            set
            {
                if (_userName != value)
                {
                    _userName = value;
                    RaisePropertyChanged("UserName");
                }
            }
        }


        private string _nickName;
        public string NickName
        {
            get { return _nickName; }
            set
            {
                if (_nickName != value)
                {
                    _nickName = value;
                    RaisePropertyChanged("NickName");
                    RaisePropertyChanged("PrettyName");
                }
            }
        }


        private SolidColorBrush _fontColor;
        public SolidColorBrush FontColor
        {
            get { return _fontColor; }
            set
            {
                if (_fontColor != value)
                {
                    _fontColor = value;
                    RaisePropertyChanged("FontColor");
                }
            }
        }
        private FontWeight _fontWeight;
        public FontWeight FontWeight
        {
            get { return _fontWeight; }
            set
            {
                if (_fontWeight != value)
                {
                    _fontWeight = value;
                    RaisePropertyChanged("FontWeight");
                }
            }
        }

        private FontStyle _fontStyle;
        public FontStyle FontStyle
        {
            get { return _fontStyle; }
            set
            {
                if (_fontStyle != value)
                {
                    _fontStyle = value;
                    RaisePropertyChanged("FontStyle");
                }
            }
        }

        private bool _isUserNameVisible;
        public bool IsUserNameVisible
        {
            get { return _isUserNameVisible; }
            set
            {
                if (_isUserNameVisible != value)
                {
                    _isUserNameVisible = value;
                    RaisePropertyChanged("IsUserNameVisible");
                }
            }
        }

        public string PrettyName
        {
            get { return !String.IsNullOrEmpty(NickName) ? NickName : UserName; } //string.Format("{0} ({1})", !String.IsNullOrEmpty(NickName) ? NickName : UserName, TimeStamp.ToShortTimeString()); }
        }

        

        private string _messageText;
        public string MessageText
        {
            get
            {
                return _messageText;
            }
            set
            {
                if (value != this._messageText)
                {
                    this._messageText = value;
                    RaisePropertyChanged("MessageText");
                }
            }
        }
        public MessageModel(string userID, DateTime timeStamp)
        {
            this.UserID = userID;
            this.UserName = UserID.Remove(userID.IndexOf("#"));
            this.TimeStamp = timeStamp;
        }
        public MessageModel()
        {

        }
        protected virtual void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
